package com.example.backend.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Value("${spring.datasource.message-db.url}")
    private String messageDbUrl;

    @Value("${spring.datasource.message-db.username}")
    private String messageDbUsername;

    @Value("${spring.datasource.message-db.password}")
    private String messageDbPassword;

    @Value("${spring.datasource.game-message-db.url}")
    private String gameMessageDbUrl;

    @Value("${spring.datasource.game-message-db.username}")
    private String gameMessageDbUsername;

    @Value("${spring.datasource.game-message-db.password}")
    private String gameMessageDbPassword;

    @Bean(name = "messageDataSource")
    public DataSource messageDataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl(messageDbUrl);
        dataSource.setUsername(messageDbUsername);
        dataSource.setPassword(messageDbPassword);
        return dataSource;
    }

    @Bean(name = "gameMessageDataSource")
    public DataSource gameMessageDataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl(gameMessageDbUrl);
        dataSource.setUsername(gameMessageDbUsername);
        dataSource.setPassword(gameMessageDbPassword);
        return dataSource;
    }
}
